import Vuex from 'vuex'
import Vue from 'vue'

import api from  '../components/api'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        user: {
            name: 'blink-photo',
            role: -1
        }
    },
    mutations: {
        updateInfo (state, user) {
            state.user = user
            window.__ToKeN__ = user.token
        }
    },
    actions: {
        async GetUserInfo ({commit}) {
            let res = await api.getUserInfo()
            if (res.success) {
                commit('updateInfo', res.data)
            }
        }
    }
})

export default store